#ifndef __M_TOUCH_PAD_H__
#define __M_TOUCH_PAD_H__

#define N_TOUCH_REPORTS 2
#define N_PIXLS_BUFS 5

typedef struct
{
    int idx;
    int bufs[N_PIXLS_BUFS];
} ScrollPixlsBuf;

typedef struct
{
    int x;
    int y;
    uint32_t hold_count;
    uint32_t motionless_hold_count;
    uint8_t long_hold;
    uint8_t long_motionless_hold;
    uint8_t beginning_long_motionless_hold;

    int x_scroll_cur_pixls;
    int x_scroll_total_pixls;
    ScrollPixlsBuf x_scroll_pixlsbuf;
    uint32_t x_scroll_count;

    int y_scroll_cur_pixls;
    int y_scroll_total_pixls;
    ScrollPixlsBuf y_scroll_pixlsbuf;
    uint32_t y_scroll_count;
} TouchData;

typedef struct
{
    uint8_t old_touched;
    uint8_t current_touched;
    uint8_t pressed_touched;
    uint8_t released_touched;

    uint8_t old_x_scrolled;
    uint8_t current_x_scrolled;
    uint8_t pressed_x_scrolled;
    uint8_t released_x_scrolled;
    
    uint8_t old_y_scrolled;
    uint8_t current_y_scrolled;
    uint8_t pressed_y_scrolled;
    uint8_t released_y_scrolled;
} TouchStates;

typedef struct
{
    TouchStates states;
    TouchData old;
    TouchData current;
} TouchReaport;

typedef struct
{
    TouchReaport reaports[N_TOUCH_REPORTS];
    int reaport_num;
    int old_reaport_num;
    int back_event_mode;
    int back_event_clicked;
} TouchPad;

void resetTouch(TouchPad *pad);
void readTouch(TouchPad *pad);

#endif